package cn.jingyuan.owl.web.core;

import cn.jingyuan.owl.model.error.ErrorCode;

import java.util.Objects;

public abstract class ExCodeUtils {

    public static boolean isSuccess(ErrorCode errorCode) {
        nonNull(errorCode);
        return ExCode.SUCCESS.getCode().equals(errorCode.getCode());
    }

    public static boolean isSuccess(String code) {
        nonNull(code);
        return ExCode.SUCCESS.getCode().equals(code);
    }

    public static boolean isError(ErrorCode errorCode) {
        return !isSuccess(errorCode);
    }

    public static boolean isError(String code) {
        return !isSuccess(code);
    }

    public static boolean matchFailure(ErrorCode errorCode) {
        nonNull(errorCode);
        return ExCode.FAILURE.getCode().equals(errorCode.getCode());
    }

    public static boolean matchFailure(String code) {
        nonNull(code);
        return ExCode.FAILURE.getCode().equals(code);
    }

    public static void nonNull(ErrorCode errorCode) {
        Objects.requireNonNull(errorCode, "'errorCode' must be not null");
    }

    public static void nonNull(String code) {
        Objects.requireNonNull(code, "'code' must be not null");
    }

}
